<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author: Author: HCZ <huangchengze@etrol.com>
// +----------------------------------------------------------------------

namespace app\admin\controller;

use app\common\controller\Admin;
use app\admin\controller\api\Config as ConfigApi;
use think\config\driver\Json;
use think\Cache;

/**
 * 系统配置
 * @package app\admin
 */
class Config  extends Admin{
	protected $api;
	
	public function _initialize()
	{
		parent::_initialize();
		$this->api = new ConfigApi();
	}
	
	/**
	 * 首页
	 */
	public function index(){
		$groups = model('Config')->group('group')->column('group');
		$this->assign('groups',$groups);
		return $this->fetch();
	}
	
	/**
	 * 新增配置信息
	 * @return \think\response\Json
	 */
	public function add(){
		if(IS_POST){
			return $this->api->add(input('post.'));
		}
		$this->assign('type',model('Config')->type);
		return $this->fetch();
	}
	
	/**
	 * 编辑配置信息
	 * @param string $id
	 * @return Json
	 */
	public function edit($id = null){
		return $this->api->edit(input('post.'),$id);
	}
	
	public function del($id = null){
		return $this->api->del($id);
	}
	/**
	 * 导航图
	 */
	public function aerialphoto(){
		return $this->api->getAerialPhoto();
	}
	
	public function configList($group = null){
		return $this->api->getConfigList($group);
	}
	/**
	 * 新增导航图
	 */
	public function addPhoto(){
		if(IS_POST){
			return $this->api->addAerialPhoto(input('post.'));
		}
		return $this->fetch();
	}
	
	/**
	 * 编辑导航图
	 * @param string $id
	 * @return mixed
	 */
	public function editPhoto($id = null){
		if(IS_POST){
			return $this->api->editAerialPhoto(input('post.'),$id);
		}
		$info = $this->api->getAerialPhoto($id)->getData();
		$this->assign('info',$info['data']);
		return $this->fetch();
	}
	
	/**
	 * 删除导航图
	 * @param string $id
	 * @return \think\response\Json
	 */
	public function delPhoto($id = null){
		return $this->api->delAerialPhoto($id);
	}
	
	
	public function clear(){
		Cache::clear();
		return json(['code'=>1,'msg'=>'缓存清空']);
	}
}
